/**
 * Created by nqldy on 16/1/20.
 */

var aifsTemplate = (function() {
	template.config("cache",false);
    /**
     * 获取模板文本
     * @param url
     * @param callback
     */
    var getTemplate = function(url, callback) {
        Ajax({
            isMask: true,
            loadMsg: "加载页面中",
            type : 'get',
            dataType : "text",
            cache : true,
            url: contextPath + url,
            success: function(tplText) {
                if ($.isFunction(callback)) {
                    callback(tplText);
                }
            }
        });
    };
    /**
     * 获取拼装后的html文本
     * @param url
     * @param data
     * @param callback
     */
    var getHtml = function(url, data, callback) {
        data = $.extend(data, {"ctx": contextPath});
        getTemplate(url, function(tplText) {
        	var render = template.compile(tplText);
            var html = render(data);
            if ($.isFunction(callback)) {
                callback(html);
            }
        	aifsWindow.tipResize();
        });
    };
    var loadHtml = function(templeId, data,destDom,callback) {
    	var html = template(templeId, data);
    	if(destDom != null){
    		$(destDom).html(html);
    	}
    	aifsWindow.tipResize();
    	if ($.isFunction(callback)) {
            callback(html,data);
        }
    };
    return {
        getTemplate: getTemplate,
        getHtml: getHtml,
        loadHtml:loadHtml
    };
}());
